<section class="section contact-section bg-white">
  <div class="container">
    <div class="title-box">
      <h1>CONTACT<br />联系我们</h1>
      <p>免费定制推广营销策略，留下您的联系方式</p>
    </div>
    <div class="contact-box">
      <div class="contact-content">
        <ul class="contact-info">
          <li>
            <label>联系人</label>
            <p>{$basic.username}</p>
          </li>
          <li>
            <label>电话</label>
            <p>{$basic.mobile}</p>
          </li>
          <li>
            <label>QQ</label>
            <p>{$basic.qq}</p>
          </li>
          <li>
            <label>电子邮箱</label>
            <p>{$basic.email}</p>
          </li>
        </ul>
        <div class="qrcode-box">
          <div class="qrcode-item">
            <img src="{$basic.qq_code}" alt="联系人QQ二维码" />
            <span>联系人QQ二维码</span>
          </div>
          <div class="qrcode-item">
            <img src="{$basic.account_code}" alt="公众号" />
            <span>公众号</span>
          </div>
        </div>
        <a class="contact-btn" href="javascript:;">商务合作方式</a>
      </div>
      <div class="contact-form">
        <h2>您的联系方式</h2>
        <div class="contact-input">
          <input
            type="text"
            name="username"
            value=""
            placeholder="请输入您的称呼"
          />
          <input
            type="text"
            name="email"
            value=""
            placeholder="请输入您的邮箱地址"
          />
          <input
            type="text"
            name="mobile"
            value=""
            placeholder="请输入您的联系方式  "
          />
          <input
            type="text"
            name="wechat"
            value=""
            placeholder="请输入您的微信号码"
          />
        </div>
        <textarea
          rows="4"
          name="description"
          value=""
          placeholder="请输入您的需求描述"
          width="100%"
          height="100%"
        ></textarea>
        <a class="contact-submit" href="javascript:;" onclick="submit()"
          >提 交</a
        >
      </div>
    </div>
  </div>
</section>
<script>
  function submit() {
    var username = $(".contact-input input[name=username]").val();
    var email = $(".contact-input input[name=email]").val();
    var mobile = $(".contact-input input[name=mobile]").val();
    var wechat = $(".contact-input input[name=wechat]").val();
    var description = $(".contact-form textarea[name=description]").val();

    if (!username || !email || !mobile || !wechat || !description) {
      layer.msg("您的联系方式信息不周全");
      return false;
    }
    if (!/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile)) {
      layer.msg("手机号码有误，请重填");
      return false;
    }
    if (
      !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email)
    ) {
      layer.msg("邮箱格式有误，请重填");
      return false;
    }
    $.ajax({
      url: "/message",
      method: "POST",
      data: {
        username: username,
        email: email,
        mobile: mobile,
        wechat: wechat,
        description: description,
      },
      success: function (res) {
        if (res.code) {
          layer.alert(res.msg, { icon: 2 });
        } else {
          layer.msg(res.msg, { icon: 1, time: 2000 }, function () {
            window.location.reload();
          });
        }
      },
    });
  }
</script>
